package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Material;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.query.MaterialQuery;
import com.by.service.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author xiaokun
 * @className MaterialController
 * @description
 * @date 2024-09-19 17:19
 * @versioN 0.1
 * @since jdk11
 */
@RestController
@Api(tags = "查询材质")
@RequestMapping("/v1")
public class MaterialController extends BaseController {

    @Autowired
    MaterialService materialService;

    @ApiOperation("材质查询")
    @PostMapping("/material/query")
    public ResultBean queryMaterial(@RequestBody MaterialQuery materialQuery){
        Map map= BeanUtil.beanToMap(materialQuery);
        PageBean bean=materialService.query(map);
        return success("材质列表",bean);
    }

    @ApiOperation("新增材质")
    @PostMapping("/material")
    public ResultBean saveMaterial(@RequestBody Material material){
        int rs=materialService.save(material);
        return success("保存成功",rs);
    }

    @ApiOperation("编辑材质")
    @PutMapping("/material")
    public ResultBean updateMaterial(@RequestBody Material material){
        int rs=materialService.update(material);
        return success("修改成功",rs);
    }

    @ApiOperation("删除材质")
    @DeleteMapping("/material")
    public ResultBean deleteMaterial(@RequestParam(name = "id",required = true,defaultValue = "0")int id){
        int rs=materialService.delete(id);
        return success("删除成功",rs);
    }
}
